package posti.test.swf.web.action;

public class BeanMapperSupport implements BeanMapper {
	private MappingsFactory mappingsFactory;

	public BeanMapperSupport(MappingsFactory mappingsFactory) {
		this.mappingsFactory = mappingsFactory;
	}

	public Object toDomainObject(String mappingName, Object dto) {
		Mapping mapping = mappingsFactory.getMapping(mappingName);
		return mapping.toDomainObject(dto);
	}

	public Object toDomainObject(Object dto) {
		String className = dto.getClass().getName();
		return this.toDomainObject(className, dto);
	}

	public Object toDTO(String mappingName, Object object) {
		Mapping mapping = mappingsFactory.getMapping(mappingName);
		return mapping.toDTO(object);
	}

	public Object toDTO(Object object) {
		String className = object.getClass().getName();
		return this.toDTO(className, object);
	}
}
